%% dXt=int SIGMAt dW  sigmat=W case number 231
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=231;
% index J for X
alphaK=20; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=alpharow*betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=0;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=0;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)

%% dXt=int SIGMAt dW sigmat=OU case number 232
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=232;
% index J for X
alphaK=20; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=alpharow*betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)


%% dXt=SIGMAt^2dt  sigmat=OU case number 222
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=222;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK); eye(betaK)];
alphas = [zeros(1,betaK); eye(betaK); 2*eye(betaK) ;index2(betaK)];
fname='alphas'; save(fname,'alphas'); fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(size(alphas,1),1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)

%% dXt=SIGMAt^2dt  sigmat=W case number 221
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=221;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK); eye(betaK)];
alphas = [zeros(1,betaK); eye(betaK); 2*eye(betaK) ;index2(betaK)];
fname='alphas'; save(fname,'alphas'); fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(size(alphas,1),1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=0;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=0;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)


%% dXt=SIGMAtdt  sigmat=OU case number 212
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=212;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)


%% dXt=SIGMAtdt   sigmat=W case number 211
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=211;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=20;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=0;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=0;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)



%% dXt=SIGMAtdt
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=1;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=50;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)
%% dXt=SIGMA^2tdt
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=2;
% index J for X
% % % alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
% % % fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=70;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); %alpharow=size(alphas,1);
%row=alpharow*betarow;
row=betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)
%% dXt=SIGMAtdW
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=3;
% index J for X
alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=70;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=alpharow*betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)

%% dXt=-1/2SIGMAT^2dt+SIGMAtdW
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=4;
% index J for X
alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=50;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=alpharow*betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)
%% dXt=-1/2SIGMAT^2dt+SIGMAt(cdW1+ddW2)
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=5;
% index J for X
alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=50;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=alpharow*betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
% sig=zeros(num+1,betaK+1);
% sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% parameters of two BMs
c=1;d=1; para=[c,d,num];
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)
%% dXt=SIGMAtdW2
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=5;
% index J for X
alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% index J for sigma
betaK=80;  betas = [zeros(1,betaK);eye(betaK)];
fname='betas';  save(fname,'betas');
% time T
T = 1/2;
% construct orthogoal basis in L2[0,t]
orthbasis(T);
% initial condition for X
betarow=size(betas,1); alpharow=size(alphas,1);
row=betarow;
X0=zeros(row,1);   X0(1)=0;
% initial condition for sigma
sig0=zeros(size(betas,1),1); sig0(1)=1;
% time mesh 
num=50;
tspan = linspace(0,T,num+1);
% ms' value
msvalue(num)
% solver of sigma
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
% % % %parameters of ou
a=1;m=1;b=1; para=[a,m,b,num];
disp('sloving 5th sigma')
tic
[time,sig] = ode45(@randomOU,tspan,sig0,[],para);
toc
sig=zeros(num+1,betaK+1);
sig(:,1)=1;
fname='sigma';
save(fname,'sig');
% solver of X
disp('sloving X')
tic
[time,X]   = ode45(@randomtest,tspan,X0,[],num,casenum);
toc
% error
%meanerr(time',y,R,sig,y0,Y/numpath)
varitest(time',X,a,m,b,sig0(1),X.*X,casenum)
%varXOU(time',X,a,m,b,X0(1),X.*X)